#include <bits/stdc++.h>

#define ll long long
const int INF = 1e9;
using namespace std;
void solve() {
	int n = 0;
	cin >> n;
	vector<int>h(n+1, 0);
	vector<int>dp1(n + 1, 0);
	vector<int>dp2(n + 1,0);
	for (int i = 1; i <= n; i++) {
		cin >> h[i];
	}
	
	for (int i = 1; i <= n; i++) {
		int max_length = 0;
		for (int j = 1; j < i; j++) {
			if (h[j] < h[i]) {
				max_length = max(max_length, dp1[j]);
			}
		}
		dp1[i] = max_length + 1;
	}
	for (int i = n; i > 0; i--) {
		int max_length = 0;
		for (int j = n; j > i; j--) {
			if (h[j] < h[i]) {
				max_length = max(max_length, dp2[j]);
			}
		}
		dp2[i] = max_length + 1;
	}
	int ans = -1;
	for (int i = 1; i <= n; i++) {
		ans = max(dp1[i] + dp2[i] - 1, ans);
	}
	cout << n-ans;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	solve();
	return 0;
}